#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;
    long long dp[10000] = { 0 };
    long long result[10000];
    dp[1] = 1;
    long long t = 0x3f3f3f3f;
    t = min(t, (long long)n - 1);
    result[0] = n;
    result[1] = n - 1;
    for (int i = 2;i < 10000;i++)
    {
        dp[i] = dp[i - 1] + dp[i - 2];
        result[i] = n - dp[i] > 0 ? n - dp[i] : dp[i] - n;
        t = min(t, result[i]);
    }
    cout << t;




    return 0;
}

//long  long